﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class admin_Templates_Other : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }

    private  void bind()
    {
        string strName = Base.GetRequest.GetQueryStringValue("t");
        Base.XMLProcess xp = new Base.XMLProcess("xml/Template.xml");
        string strRemarks = Base.XMLProcess.Read("xml/Template.xml", "/template/other/mode[@name='" + strName.Trim() + "']", "remarks");
        string strUrl = Base.XMLProcess.Read("xml/Template.xml", "/template/other/mode[@name='" + strName.Trim() + "']", "url");
        string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + strUrl;

        StringBuilder builder = new StringBuilder();
        if (CheckFile(path))
        {
            using (System.IO.StreamReader reader = new System.IO.StreamReader(path, Encoding.Default))
            {
                builder.Append(reader.ReadToEnd());
                reader.Close();
            }
            //this.Title.Text = Request.QueryString["url"];
            //this.Title.ReadOnly = true;
            this.txtContent.Value = builder.ToString();
            this.ViewState["path"] = path;
            this.txtRemarks.Text = strRemarks;
            this.lblName.Text = strName;
        }
        else
        {
            //ShowMessage("请求的页面不存在！", "../index_center.aspx");
            ShowMessage(strUrl, "../index_center.aspx");
            return;
        }
    }


    /// <summary>
    /// 保存修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
       
        Base.XMLProcess.Update("xml/Template.xml", "/template/other/mode[@name='" + this.lblName.Text + "']", "remarks", this.txtRemarks.Text.Trim());
        System.IO.File.WriteAllText(this.ViewState["path"].ToString(), this.txtContent.Value,Encoding.Default);
        Response.Redirect("OtherList.aspx");

    }
}
